package com.darksider.darkotlin.ui

import android.os.Bundle
import com.darksider.darkotlin.R
import com.darksider.darkotlin.base.BaseActivity
import com.darksider.darkotlin.extras.start
import com.darksider.darkotlin.ui.main.MainActivity
import com.darksider.darkotlin.utils.RxHelper
import kotlinx.android.synthetic.main.activity_splash.*

class SplashActivity : BaseActivity() {

    private var mIsSkip = false

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
        initView()
    }

    private fun initView() {
        tag_skip.setTagClickListener { pos, text, mode -> _doSkip() }
        RxHelper.countdown(5)
                .compose(bindToLifecycle())
                .subscribe({ num -> tag_skip.text = "跳过 $num" },
                        { e -> _doSkip() },
                        { _doSkip() })
    }


    private fun _doSkip() {
        if (!mIsSkip) {
            mIsSkip = true
            start<MainActivity>(true)
        }
    }

    override fun onBackPressed() {

    }
}
